package com.lt.utils;

import android.os.Build;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池
 * @author LiuTong
 */

public class ThreadPoolUtils {
    private ExecutorService executors;
    private final int coreSize = 3;
    private final int maxSize = 5;
    private final long keepTime = 3000;
    private final TimeUnit timeUnit = TimeUnit.SECONDS;
    private BlockingDeque<Runnable> blockingDeque = new LinkedBlockingDeque<>();

    private static ThreadPoolUtils instance;

    public static ThreadPoolUtils getInstance() {
        if(instance == null){
            synchronized (ThreadPoolUtils.class){
                if(instance == null){
                    instance = new ThreadPoolUtils();
                }
            }
        }
        return instance;
    }


    private ThreadPoolUtils(){
        executors = new ThreadPoolExecutor(
                coreSize,
                maxSize,
                keepTime,
                timeUnit,
                blockingDeque);
    }

    public void runTask(Runnable task){
        executors.submit(task);
    }

}
